package com.example.Lezedata.ui.dataPage;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TableLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.widget.ViewPager2;

import com.example.Lezedata.R;
import com.example.Lezedata.ui.annPage.AnnListFragment;
import com.example.Lezedata.ui.annPage.AnnPageAdapter;
import com.example.Lezedata.ui.fragment.BaseFragment;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

import bid.Bid;
import bid.SystemAnnouncement;

import static bid.Bid.BeeVersion;

public class DataPageSuperFragment extends BaseFragment {
    public static DataPageSuperFragment newInstance() {
        return new DataPageSuperFragment();
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.tab_data_super_page_fragment, container, false);
    }


    TabLayout tabLayout;
    ViewPager2 viewPager2;
    @Override
    public void onViewCreated(@NonNull @NotNull View view, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState){
        super.onViewCreated(view, savedInstanceState);
        tabLayout = findViewById(R.id.TabLayout);
        viewPager2 = findViewById(R.id.ViewPager2);

        //设置标题
        final ArrayList<String> titleList = new ArrayList<>();
        titleList.add("主网数据");
        titleList.add("空投数据");

        BeeVersion[] announceTypes = new BeeVersion[]{
                BeeVersion.BV_100,
                BeeVersion.BV_062,
        };

        ArrayList<Fragment> fragments = new ArrayList<>();
        for(int i = 0; i<announceTypes.length; i++) {
            DataPageFragment fragment = new DataPageFragment();
            fragment.beeVersion = announceTypes[i];
            fragments.add(fragment);
        }

        //设置上下滑动
        viewPager2.setOrientation(ViewPager2.ORIENTATION_HORIZONTAL);

        //定义适配器
        //设置自定义的适配器必需继承FragmentStateAdapter
        AnnPageAdapter myAdapter = new AnnPageAdapter(this.getActivity(), fragments, titleList);
        viewPager2.setAdapter(myAdapter);
        new TabLayoutMediator(tabLayout, viewPager2, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(titleList.get(position));
            }
        }).attach();
    }
}
